//
//package com.bcqn.aspect;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.serializer.SerializerFeature;
//import com.bcqn.utils.IpUtil;
//import eu.bitwalker.useragentutils.UserAgent;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.util.StringUtils;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.net.URLDecoder;
//import java.nio.charset.StandardCharsets;
//import java.util.Objects;
//
///**
// * ControllerLogAspect
// *
// * @author Kelly
// * @version v1.0
// * @date 2020/4/19 16:27
// */
//@Aspect
//@Configuration
//@Slf4j
//public class ControllerLogAspect {
//
//    @Pointcut("execution(*  *..*.controller..*.*(..))")
//    public void log() {
//
//    }
//
//    /**
//     * 输出请求日志
//     * @param pjp ProceedingJoinPoint
//     * @return Object
//     * @throws Throwable 异常
//     */
//    @Around("log()")
//    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
//        //记录请求开始执行时间
//        long begin = System.currentTimeMillis();
//        //获取请求信息
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = Objects.requireNonNull(attributes).getRequest();
//        //请求IP
//        String remoteAddress = IpUtil.getIpAddr(request);
//        //请求方法GET、POST
//        String method = request.getMethod();
//        String params = "";
//        if (RequestMethod.POST.name().equals(method)) {
//            Object[] args = pjp.getArgs();
//            params = JSON.toJSONString(args, SerializerFeature.WriteMapNullValue);
//            if(args.length<=0){
//                params = JSON.toJSONString(request.getParameterMap());
//            }
//        } else if (RequestMethod.GET.name().equals(method)) {
//            if(!StringUtils.isEmpty(request.getQueryString())){
//                params = request.getQueryString();
//            }
//        }
//        String header = request.getHeader("User-Agent");
//        UserAgent userAgent = UserAgent.parseUserAgentString(header);
//        Object result = pjp.proceed();
//        log.info("{}:{} IP:{}[{}]请求{}完成，请求参数为==>[{}]，返回结果为==>[{}]，耗时{}ms！",
//                userAgent.getOperatingSystem().toString(), userAgent.getBrowser().toString(),
//                remoteAddress, request.getMethod(), pjp.getSignature().toString(),
//                URLDecoder.decode(params, StandardCharsets.UTF_8.name()),JSON.toJSON(result),(System.currentTimeMillis() - begin));
//        return result;
//    }
//}
